<%@ page contentType="text/html;charset=UTF-8" %>
<%
    if (request.getSession().getAttribute("admin_username") != null) {
        response.sendRedirect("/admin/index.jsp");
    }
%>
<html>
<head>
    <title>管理员登录</title>
    <%
        if (request.getSession().getAttribute("admin_login_error") != null) { // 登录错误
            out.print("<script>alert(\"" + (request.getSession().getAttribute("admin_login_error")) + "\");</script>"); // 弹窗提示
            request.getSession().removeAttribute("admin_login_error"); // 删除会话
            out.print("<script>location.reload();</script>"); // 刷新网页
        } else {
    %>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0,  user-scalable=0">
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/static/admin/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/admin/css/login.css">
    <script>
        /**
         * 点击验证码刷新，在网页加载完成之后再加载此函数
         */
        window.onload = function () {
            document.getElementById("codeValidate").addEventListener("click", () => {
                const url = document.getElementById("codeValidate").getAttribute("src");
                const random = Math.random();
                document.getElementById("codeValidate").setAttribute("src", url + "?" + random);
            }, false);
        }
    </script>
</head>
<body>
<div class="login">
    <div class="container-login100">
        <div class="wrap-login100">
            <div class="login100-pic js-tilt" data-tilt>
                <img src="${pageContext.request.contextPath}/static/admin/img/login_title.png" alt="img">
            </div>
            <form method="post" autocomplete="off" name="login" id="login-form" class="login100-form validate-form"
                  action="deal/login.jsp">
            <span class="login100-form-title"><span style="color: #f60; ">图书馆</span> 管理中心
				</span>
                <div class="wrap-input100 validate-input">
                    <label>
                        <input class="input100" type="text" name="admin_username" placeholder="用户名">
                    </label>
                    <span class="focus-input100"></span>
                    <span class="symbol-input100">
						<i class="fa fa-user" aria-hidden="true"></i>
					</span>
                </div>
                <div class="wrap-input100 validate-input">
                    <label>
                        <input class="input100" type="password" name="admin_password" placeholder="密　码">
                    </label>
                    <span class="focus-input100"></span>
                    <span class="symbol-input100">
						<i class="fa fa-lock" aria-hidden="true"></i>
					</span>
                </div>
                <div class="wrap-input100 validate-input">
                    <label>
                        <input class="input100" type="text" name="validateCode" placeholder="验证码">
                    </label>
                    <span class="focus-input100"></span>
                    <span class="symbol-input100">
						<i class="fa fa-lock" aria-hidden="true"></i>
					</span>
                </div>
                <div class="wrap-input100 validate-input">
                    <img src="${pageContext.request.contextPath}/validateCode" height="50px" class="input100"
                         id="codeValidate" alt="验证码">
                    <span class="focus-input100"></span>
                    <span class="symbol-input100">
						<i class="fa fa-lock" aria-hidden="true"></i>
					</span>
                </div>
                <div class="container-login100-form-btn">
                    <button type="submit" class="login100-form-btn">
                        提交
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<%
    }
%>
</body>
</html>
